﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using WebApi2020.DB;
using WebApi2020.Models;

namespace WebApi2020.Controllers
{
    /// <summary>
    /// 系统用户接口
    /// </summary>
    [Route("[controller]/[action]")]
    [ApiController]
    public class SysUserController : ControllerBase
    {
        private readonly MyContext _context;
        /// <summary>
        /// 
        /// </summary>
        /// <param name="context"></param>
        public SysUserController(MyContext context)
        {
            _context = context;
        }

        /// <summary>
        /// 根据ID查询用户
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        // GET: api/SysUser/5
        [HttpPost]
        public async Task<ActionResult<SysUser>> GetUserByID(SysUser user)
        {
            var sysUser = await _context.FindAsync<SysUser>(user.Id);

            if (sysUser == null)
            {
                return NotFound();
            }

            return Ok(sysUser);
        }
    }
}
